package edu.nf.project.services.employeeAndCustomerInformation.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import edu.nf.project.entitys.entity.employeeAndCustomerInformation.convention.ShippingAddress;
import edu.nf.project.mappers.employeeAndCustomerInformation.convention.ShippingAddressMapper;
import edu.nf.project.services.employeeAndCustomerInformation.DefaultAddressService;
import edu.nf.project.services.employeeAndCustomerInformation.ShippingAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author CSY
 * @date 2025 - 06 - 08
 */
@Service
public class ShippingAddressServiceImpl implements ShippingAddressService {
    @Autowired
    private ShippingAddressMapper shippingAddressMapper;

    @Autowired
    private DefaultAddressService defaultAddressService;

    @Override
    public List<ShippingAddress> listAddressByUserId(int uId) {
        LambdaQueryWrapper<ShippingAddress> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShippingAddress::getUId,uId);
        return shippingAddressMapper.selectList(queryWrapper);
    }

    @Override
    public ShippingAddress getAddressByAddressId(int addressId) {
        return shippingAddressMapper.selectById(addressId);
    }

    @Override
    public void addAddress(ShippingAddress address) {
        shippingAddressMapper.insert(address);
        if (address.getIsDefault()){
            defaultAddressService.isDefaultExit(address);
        }
    }

    @Override
    public void updateAddress(ShippingAddress address) {
        if (address.getIsDefault()){
            defaultAddressService.isDefaultExit(address);
        }
        shippingAddressMapper.updateById(address);
    }

    @Override
    public void deleteAddress(int addressId) {
        shippingAddressMapper.deleteById(addressId);
    }


}
